<template>
  <div
    class="index-table"
    v-for="item in templateData?.personnelAssessmentOptionDimensionality"
    :key="item.type"
  >
    <div class="index-card" v-if="item.type === 1">
      <ConditionBox>
        <template #left>
          <div class="title">{{ item.name }}</div>
          维度权重：{{ item.weight }}
        </template>
        <template #right></template>
      </ConditionBox>
      <a-divider />
      <IndexTable
        v-model:data="templateData.personnelKeyPerformanceIndexLibrary"
        :upperLimitScore="templateData.upperLimitScore"
      />
    </div>
    <div class="index-card" v-if="item.type === 2">
      <ConditionBox>
        <template #left>
          <div class="title">{{ item.name }}</div>
          维度权重：{{ item.weight }}
        </template>
        <template #right></template>
      </ConditionBox>
      <a-divider />
      <AbilityIndeTable
        v-model:data="templateData.personnelAbilityQualityIndexLibrary"
        :review="props.review"
        :upperLimitScore="templateData.upperLimitScore"
      />
    </div>
    <div class="index-card" v-if="item.type === 3">
      <ConditionBox>
        <template #left>
          <div class="title">{{ item.name }}</div>
          维度权重：{{ item.weight }}
        </template>
        <template #right></template>
      </ConditionBox>
      <a-divider />
      <WorkPlanTable
        v-model:data="templateData.personnelWorkPlanIndexLibrary"
        :upperLimitScore="templateData.upperLimitScore"
        :review="props.review"
      />
    </div>
    <div class="index-card" v-if="item.type === 4">
      <ConditionBox>
        <template #left>
          <div class="title">{{ item.name }}</div>
          维度权重：{{ item.weight }}
        </template>
        <template #right></template>
      </ConditionBox>
      <a-divider />
      <TargetTable
        v-model:data="templateData.personnelTargetIndexLibrary"
        :upperLimitScore="templateData.upperLimitScore"
        :review="props.review"
        :showRowSelection="props.showRowSelection"
        v-model:returnData="templateData.personnelTargetIndexLibraryUse"
        :onlyShowSelected="onlyShowSelected"
        :returnTemp="returnTemp"
        :args="props.args"
        :templateData="templateData"
        v-model:delTargetData="delTargetData"
        v-model:selectedTargetIds="selectedTargetIds"
      />
    </div>
    <div class="index-card" v-if="item.type === 5">
      <ConditionBox>
        <template #left>
          <div class="title">{{ item.name }}</div>
          <!-- 维度权重：{{ item.weight }} -->
        </template>
        <template #right></template>
      </ConditionBox>
      <a-divider />
      <AddSubtractTable
        v-model:data="templateData.personnelAddSubtractIndexLibrary"
        :upperLimitScore="templateData.upperLimitScore"
        :review="props.review"
      />
    </div>
    <div class="index-card" v-if="item.type === 6">
      <ConditionBox>
        <template #left>
          <div class="title">{{ item.name }}</div>
          <!-- 维度权重：{{ item.weight }} -->
        </template>
        <template #right> </template>
      </ConditionBox>
      <a-alert type="warning" closable>
        <template #title> 请注意！ </template>
        “否决指标”通常指在评估或考核过程中使用的一种特殊标准或维度。它是一种严格的标准，如果在评估中未达到或未满足，则可能对整体表现或成果产生否定的影响且结果为反向操作。
        （1）选项否决：只有有一项是达标，整个考核结果不达标，反之是不达标，整个考核结果达标，不参与计算。
        （2）输入扣分：类似减分项，考核结果总分减去扣分。
      </a-alert>
      <a-divider />
      <VetoTable
        v-model:data="templateData.personnelVetoIndexLibrary"
        :review="props.review"
      />
    </div>
  </div>
</template>

<script setup lang="ts">
import { cloneDeep } from 'lodash';
import { PerformanceAppraisal } from '@/apis/management/performance/baseSetting/template/type';
import IndexTable from './Tool/AssessmentTable/index.vue';
import AbilityIndeTable from './Tool/AbilityIndeTable/index.vue';
import WorkPlanTable from './Tool/WorkPlanTable/index.vue';
import TargetTable from './Tool/TargetTable/index.vue';
import AddSubtractTable from './Tool/AddSubtractTable/index.vue';
import VetoTable from './Tool/VetoTable/index.vue';
import type {
  ProbationExamine,
  ReturnIndex
} from '@/apis/human/base/variationManager/probation/type';
import { PerformanceAssessmentTemplateDimensionality } from '@/apis/management/performance/baseSetting/template/type';
import { useVModel } from '@vueuse/core';

const props = withDefaults(
  defineProps<{
    data: ProbationExamine;
    /**
     * 0：默认，显示操作
     * 1：显示操作项（适用考核设置时），2：不显示操作项（适用预览时），3：不显示操作项，评分人显示格式不同（适用我的考核）
     */
    review?: number;
    showRowSelection?: boolean;
    returnIndex: ReturnIndex;
    onlyShowSelected: boolean;
    returnTemp: number;
    args?: {
      showAdd?: boolean; //显示新增
      showOperation?: boolean; //显示操作
      scorerType?: number; //评分人显示样式。0集成，1区分
      showScoreInput?: boolean;
      showReason?: boolean;
      showIndexScore?: boolean;
    };
    delTargetData?: any;
    selectedTargetIds?: number[];
  }>(),
  {
    args: () => ({
      showAdd: true,
      showOperation: true,
      scorerType: 0,
      showScoreInput: false,
      showReason: false
    })
  }
);
const emit = defineEmits([
  'handleOk',
  'update:data',
  'update:returnIndex',
  'update:delTargetData',
  'update:selectedTargetIds'
]);
const templateData = useVModel(props, 'data', emit) || [];
const returnData = useVModel(props, 'returnIndex', emit);
const delTargetData = useVModel(props, 'delTargetData', emit);
const selectedTargetIds = useVModel(props, 'selectedTargetIds', emit);
</script>

<style lang="less" scoped>
.index-table {
  // margin: 20px;
  .index-card {
    margin: 20px 0;
    box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.12);
    padding: 20px;
    border-radius: 2px;
    .title {
      font-weight: 600;
      font-size: 18px;
    }
  }
}
</style>
